﻿Ext.namespace("Swfu");
Ext.namespace("Swfu.BackMgr");

Swfu.BackMgr.EmpProfileMgr = Ext.extend(Ext.grid.GridPanel, {
    initComponent: function () {
        var ddlDeptEmpProfile = new Ext.form.TreeField({
            id: 'treeDeptEmpProfile', name: 'treeDeptEmpProfile',
            dataUrl: '/dept.mvc/DeptTreeByEmp',
            syncParams: 'controllerName=EmpProfile',
            listHeight: 250, width: 150
        });
        var sm = new Ext.grid.CheckboxSelectionModel({ singleSelect: true });
        var fm = Ext.form;

        var cm = new Ext.grid.ColumnModel([
			{
			    header: "工号",
			    dataIndex: 'JobNo'
			}, {
			    header: "姓名",
			    dataIndex: 'Name'
			}, {
			    header: "部门",
			    dataIndex: 'Dep'
			}, {
			    header: "分机",
			    dataIndex: 'TelExt'
			}, {
			    header: "手机",
			    dataIndex: 'Mobile'
			}, {
			    header: '身份证地址',
			    dataIndex: 'IdAddress'
			}, { header: "操作", dataIndex: 'Id', width: 130,
			    renderer: function (value) {
			        var links = [];
			        links.push('<a href="EmpInfo.aspx?empId=' + value + '" target="_blank">查看</a>');
			        //王芳:188,
			        if (",188,582,".indexOf("," + Cookies.get("empId") + ",") >= 0) {
			            links.push('<a href="#" onclick="var url =\'EmpEdit.aspx?empId=' + value + '\';window.showModalDialog(url, window, \'dialogWidth=850px;dialogHeight=650px;status=no;help=no;resizable=yes;\');Ext.getCmp(\'EmpProfileMgr\').getStore().reload();">编辑</a>');
			        }
			        return links.join("&nbsp;");
			    }
			}
		]);
        var reader = new Ext.data.JsonReader({
            totalProperty: 'totalCount', //分页使用
            root: 'data',
            autoLoad: true,
            fields: [{
                name: 'Id'
            }, {
                name: 'JobNo'
            }, {
                name: 'Name'
            }, {
                name: 'Dep'
            }, {
                name: 'TelExt'
            }, {
                name: 'Mobile'
            }, {
                name: 'IdAddress'
            }]
        });

        var ds = new Ext.data.Store({
            scopte: this,
            id: 'EmpProfileDS',
            url: '/EmpProfile.mvc/Find',
            reader: reader
        });

        Ext.apply(this, {
            id: 'EmpProfileMgr',
            plain: false,
            layout: 'fit',
            border: false,
            cm: cm,
            sm: sm,
            frame: true,
            store: ds,
            loadMask: true,
            tbar: new Ext.Panel({
                border: false,
                items: [
                { xtype: 'toolbar', items: [{
                    text: "添加",
                    tooltip: "添加新的信息",
                    iconCls: "addicon",
                    handler: function () {
                        var url = 'EmpBasicInfoTab.aspx';
                        var retVal = window.showModalDialog(url, window, 'dialogWidth=850px;dialogHeight=600px;status=no;help=no;resizable=yes;');
                        if (!isNaN(retVal)) {
                            url = 'EmpEdit.aspx?empId=' + retVal;
                            window.showModalDialog(url, window, 'dialogWidth=850px;dialogHeight=650px;status=no;help=no;');//检测数据更改>刷新?
                            ds.reload();
                        }
                    }
                }, '-', {
                    text: "重新加载数据",
                    iconCls: 'icon-redo',
                    handler: function () {
                        ds.reload();
                    } .createDelegate(this)
                }, '->', {
                    xtype: 'tbtext',
                    text: '部门:'
                }, ddlDeptEmpProfile, {
                    xtype: 'tbtext',
                    text: '姓名:'
                }, {
                    xtype: 'textfield',
                    name: 'txtName',
                    id: 'txtName',
                    emptyText: '人名的一或几个字',
                    blankText: '人名的一或几个字',
                    anchor: '100%'
                }, '-', {
                    xtype: 'tbtext',
                    text: '在职状态:'
                }, {
                    xtype: 'combo',
                    name: 'StatusId',
                    id: 'StatusId',
                    width: 100,
                    displayField: 'text',
                    valueField: 'id',
                    hiddenName: 'text',
                    hiddenId: 'id',
                    typeAhead: true,
                    mode: 'local',
                    editable: false,
                    selectOnFoucs: true,
                    triggerAction: 'all',
                    blankText: '请选择在职状态',
                    emptyText: '请选择在职状态',
                    store: new Ext.data.SimpleStore({ fields: [{ name: 'id', mapping: 0 }, { name: 'text', mapping: 1}],
                        data: [[0, '全部'], [1, '在职'], [2, '离职'], [3, '试用期'], [4, '实习期']], autoload: true
                    }),
                    listeners: { scope: this }
                }, '-', {
                    text: "查询",
                    iconCls: 'icon-search',
                    handler: function () {
                        ds.reload();
                    } .createDelegate(this)
                }]
                }
			    ]
            }),

            //分页
            bbar: new Ext.PagingToolbar({
                pageSize: 20,
                store: ds,
                displayInfo: true,
                displayMsg: '显示第 {0} 条到 {1} 条记录，共 {2} 条',
                emptyMsg: '无记录'
            })
        });
        Swfu.BackMgr.EmpProfileMgr.superclass.initComponent.apply(this, arguments);
        ds.load({
            params: {
                start: 0,
                limit: 20
            }
        });
        ds.on('beforeload', function (thiz, options) {
            var statusId = Ext.getCmp('StatusId').getValue();
            Ext.apply(thiz.baseParams, { deptId: Ext.getCmp('treeDeptEmpProfile').getValue(), name: Ext.getCmp('txtName').getValue(), statusId: statusId });
        });
    },
    render: function () {
        Swfu.BackMgr.EmpProfileMgr.superclass.render.apply(this, arguments);
        //超级管理员2,王芳经理188,朱艳华582,蔡建伟514,
        if (",2,188,582,".indexOf("," + Cookies.get("empId") + ",") == -1) {
            this.getTopToolbar().items.items[0].items.items[0].disable();
            this.getTopToolbar().items.items[0].items.items[2].disable();
        }
    }
});

Ext.reg('EmpProfileMgr', Swfu.BackMgr.EmpProfileMgr);